# -*- coding: utf-8 -*-
# owner: shenyi

# src/utils/async_utils.py
import asyncio
import functools
import click
from typing import Callable, Any

def async_command(f: Callable) -> Callable:
    """
    将异步函数包装为 Click 可执行的同步命令
    用法:
        @cli.command()
        @async_command
        async def my_command():
            await do_something()

    :param f: 异步函数 (async def)
    :return: 包装后的同步可调用对象
    """
    @functools.wraps(f)
    def wrapper(*args, **kwargs) -> Any:
        return asyncio.run(f(*args, **kwargs))
    return wrapper